<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>三审送审</title>
<link rel="stylesheet" type="text/css" href="../css/blueprint/screen.css" media="screen, projection"/>
<link rel="stylesheet" type="text/css" href="../css/blueprint/plugins/buttons/screen.css" media="screen, projection"/>
<link type="text/css" href="../css/redmond/jquery-ui-1.7.custom.css" rel="stylesheet" />
<script type="text/javascript" src="../script/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../script/jquery-ui-1.7.custom.min.js"></script>
<script type="text/javascript" src="../script/jquery.plugin.tablecross-0.1.js"></script>
<script type="text/javascript" src="../script/jquery.plugin.pageit-0.1.js"></script>
<script type="text/javascript" src="../script/jquery.plugin.ajaxtip-0.1.js"></script>
<script type="text/javascript">
    var planId;
    var queryVO = {unit: ""};
    $(document).ready(function() {
        $("#planDataTable").ajaxProccessTip();
        getPlanData(queryVO, 1, 10);
        $("#pageBar").pageListener(getPlanData, queryVO);
        $("#QUERY_SELECT").change(function() {
            if ($(this).val() == "unit") {
                $("#QUERY_TD").html('<input type="text" value="" id="QUERY_CONDITION" />');
            }
        });
        $("#QUERY_BUTTON").click(function() {
            var select = $("#QUERY_SELECT").val();
            var condition = $("#QUERY_CONDITION").val();
            if (select == "unit") {
                queryVO.unit = condition;
            }
            getPlanData(queryVO, 1, 10);
        });
        assignExpertInit();
    });

    function getPlanData(queryVO, pageIndex, pageSize) {
        $.ajax({
            type: "post",
            url: "ListNeedThirdJudgePlan.action",
            data: {"queryVO.unit": queryVO.unit, "pageVO.pageIndex": pageIndex, "pageVO.pageSize": pageSize},
            dataType: "json",
            success: function(data) {
                if (data == null) {
                    alert('非法的请求，请确认你是否有权限执行该操作，请重新登录。');
                    window.parent.location.href="../j_spring_security_logout";
                    return;
                }
                var strArr = new Array();
                for (var i = 0; i < data.planList.length; i++) {
                    strArr.push('<tr>');
                    strArr.push('<td>' + data.planList[i].registerid + '</td>');//项目登记号
                    strArr.push('<td>' + data.planList[i].prjUnit + '</td>');//项目单位
                    strArr.push('<td>' + data.planList[i].prjName + '</td>');//项目名称
                    strArr.push('<td>' + data.planList[i].prjXmxzName + '</td>');//项目性质
                    strArr.push('<td>' + data.planList[i].prjXmgm + '</td>');//项目规模
                    strArr.push('<td>' + data.planList[i].prjKzName + '</td>');//矿种
                    strArr.push('<td>' + data.planList[i].prjKcfsName + '</td>');//开采方式
                    strArr.push('<td>' + '<a href="NeedJudgePlanDetailPre.action?planId=' + data.planList[i].prjPkid + '" target="MainFrame" class="button"><img src="../css/blueprint/plugins/buttons/icons/table.png" alt=""/>明细</a> ');
                    strArr.push('<input type="hidden" class="hiddenPlanId" value="' + data.planList[i].prjPkid + '" /><button type="button" class="assignexpert-button"><img src="../css/blueprint/plugins/buttons/icons/user_go.png" alt=""/>分配专家</button></td>');//操作
                    strArr.push('</tr>');
                }
                $("#planDataBody").html(strArr.join(''));
                $("#planDataBody").tablecross('', 'odd', 'over');
                $("#pageBar").pageRender(data.pageVO.pageIndex, data.pageVO.pageSize, data.pageVO.pageNum);
                opretion();
            }
        });
    }
    function opretion() {
        $(".assignexpert-button").click(function() {
            planId = $(this).siblings(".hiddenPlanId").val();
            $.ajax({
                type: "post",
                url: "LoadAssignedExpert.action",
                data: {"planId": planId},
                dataType: "json",
                success: function(data) {
                	$(".select-expert-hidden").get(0).value = data.assignedExperts.groupleader != null ? data.assignedExperts.groupleader : "";
                	$(".select-expert-hidden").get(1).value = data.assignedExperts.expert1 != null ? data.assignedExperts.expert1 : "";
                	$(".select-expert-hidden").get(2).value = data.assignedExperts.expert2 != null ? data.assignedExperts.expert2 : "";
                	$(".select-expert-hidden").get(3).value = data.assignedExperts.expert3 != null ? data.assignedExperts.expert3 : "";
                	$(".select-expert-hidden").get(4).value = data.assignedExperts.expert4 != null ? data.assignedExperts.expert4 : "";
                	$(".select-expert-hidden").get(5).value = data.assignedExperts.expert5 != null ? data.assignedExperts.expert5 : "";
                	$(".select-expert-hidden").get(6).value = data.assignedExperts.expert6 != null ? data.assignedExperts.expert6 : "";
                	$(".select-expert-hidden").get(7).value = data.assignedExperts.expert7 != null ? data.assignedExperts.expert7 : "";
                	$(".select-expert-hidden").get(8).value = data.assignedExperts.expert8 != null ? data.assignedExperts.expert8 : "";
                	$(".select-expert-text").get(0).value = data.assignedExperts.expert0Name != null ? data.assignedExperts.expert0Name : "";
                	$(".select-expert-text").get(1).value = data.assignedExperts.expert1Name != null ? data.assignedExperts.expert1Name : "";
                	$(".select-expert-text").get(2).value = data.assignedExperts.expert2Name != null ? data.assignedExperts.expert2Name : "";
                	$(".select-expert-text").get(3).value = data.assignedExperts.expert3Name != null ? data.assignedExperts.expert3Name : "";
                	$(".select-expert-text").get(4).value = data.assignedExperts.expert4Name != null ? data.assignedExperts.expert4Name : "";
                	$(".select-expert-text").get(5).value = data.assignedExperts.expert5Name != null ? data.assignedExperts.expert5Name : "";
                	$(".select-expert-text").get(6).value = data.assignedExperts.expert6Name != null ? data.assignedExperts.expert6Name : "";
                	$(".select-expert-text").get(7).value = data.assignedExperts.expert7Name != null ? data.assignedExperts.expert7Name : "";
                	$(".select-expert-text").get(8).value = data.assignedExperts.expert8Name != null ? data.assignedExperts.expert8Name : "";
                }
            });
            $('#expert_dialog').dialog('open');
        });
    }
    function assignExpertInit() {
        var selectText;
        var selectHidden;
        $("#expert_dialog").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 370,
            modal: false,
            buttons: {
                '取消': function() {
                    $(this).dialog('close');
                },
                '确定分配': function() {
                    $.ajax({
                        url: "AssignExpert.action",
                        type: "post",
                        data:
                        {
                            "prjExperts.prjPkid": planId,
                            "prjExperts.groupleader": $(".select-expert-hidden").get(0).value,
                            "prjExperts.expert1": $(".select-expert-hidden").get(1).value,
                            "prjExperts.expert2": $(".select-expert-hidden").get(2).value,
                            "prjExperts.expert3": $(".select-expert-hidden").get(3).value,
                            "prjExperts.expert4": $(".select-expert-hidden").get(4).value,
                            "prjExperts.expert5": $(".select-expert-hidden").get(5).value,
                            "prjExperts.expert6": $(".select-expert-hidden").get(6).value,
                            "prjExperts.expert7": $(".select-expert-hidden").get(7).value,
                            "prjExperts.expert8": $(".select-expert-hidden").get(8).value
                        },
                        dataType: "json",
                        async: false,
                        success: function(data) {
                            if (data.status == "success") {
                                alert('专家分配完毕');
                                window.location.href = "ListNeedJudgePlan3.html";
                            }
                            if (data.status == "failure") {
                                alert('专家分配失败');
                            }
                        }
                    });
                    $(this).dialog('close');
                },
                '增加专家': function() {
                	if ($("#e8_li").is(":visible")) {
                        alert('最多可分配九名专家。');
                    } else {
                        if ($("#e7_li").is(":visible")) {
                            $("#e8_li").show();
                        } else {
                            if ($("#e6_li").is(":visible")) {
                                $("#e7_li").show();
                            } else {
                                if ($("#e5_li").is(":visible")) {
                                    $("#e6_li").show();
                                } else {
                                    $("#e5_li").show();
                                }
                            }
                        }
                    }
                }
            },
            close: function() {
            }
        });
        $("#select_expert_dialog").dialog({
            bgiframe: true,
            autoOpen: false,
            width: 400,
            height: 200,
            modal: true,
            buttons: {
                '取消': function() {
                    $(this).dialog('close');
                },
                '确定': function() {
                    var expertName = $("#expert_select option:selected").text();
                    var expertId = $("#expert_select option:selected").val();
                    if (expertId != "") {
                        selectText.val(expertName);
                        selectHidden.val(expertId);
                    }
                    $(this).dialog('close');
                }
            },
            close: function() {
            }
        });
        $(".select-expert-text").click(function() {
            selectText = $(this);
            selectHidden = $(this).siblings(".select-expert-hidden");
            $("#select_expert_dialog").dialog('open');
        });
        $.ajax({
            type: "post",
            url: "../expert/PrepareAssignExpert.action",
            dataType: "json",
            success: function(data) {
                var provinceArr = new Array();
                for (var i = 0; i < data.provinceList.length; i++) {
                    provinceArr.push('<option value="' + data.provinceList[i].pid + '">' + data.provinceList[i].name + '</option>');
                }
                $("#expert_province_select").append(provinceArr.join(''));
                $("#expert_province_select").change(function() {
                    if ($(this).val() != '' && $(this).val() != null) {
                        $.ajax({
                            type: "post",
                            url: "../expert/PrepareAssignExpertCityList.action",
                            data: {"provinceId": $(this).val()},
                            dataType: "json",
                            success: function(data) {
                                var cityArr = new Array();
                                cityArr.push('<option value="">选择城市</option>');
                                for (var l = 0; l < data.cityList.length; l++) {
                                    cityArr.push('<option value="' + data.cityList[l].id + '">' + data.cityList[l].name + '</option>');
                                }
                                $("#expert_city_select").html(cityArr.join(''));
                            }
                        });
                    }
                });
                var typeArr = new Array();
                for (var l = 0; l < data.typeList.length; l++) {
                    typeArr.push('<option value="' + data.typeList[l].typeCode + '">' + data.typeList[l].typeName + '</option>');
                }
                $("#expert_type_select").append(typeArr.join(''));
            }
        });
        $("#load_expert_button").click(function() {
            var city = $("#expert_city_select").val();
            var type = $("#expert_type_select").val();
            if (city != "" || type != "") {
            	if (city == "") {
                    $("#expert_province_select").val("");
                }
                $.ajax({
                    type: "post",
                    url: "../expert/GetExpertList.action",
                    data: {"queryVO.city": city, "queryVO.type": type},
                    dataType: "json",
                    success: function(data) {
                        if (data.expertList.length > 0) {
                            var strArr = new Array();
                            for (var i = 0; i < data.expertList.length; i++) {
                                strArr.push('<option value="' + data.expertList[i].expertid + '">' + data.expertList[i].expertname + '</option>');
                            }
                            $("#expert_select").html(strArr.join(''));
                        } else {
                            $("#expert_select").html('<option value="">没有专家</option>');
                        }
                    }
                });
            } else {
            	$("#expert_province_select").val("");
                alert('查询专家前，城市和类型请至少选择一个条件');
            }
        });
    }
</script>
<style type="text/css">
tr.odd td {
    background: #ecf6fc;
}
ul li {
    list-style-type: none;
}
</style>
</head>
<body>
<div id="select_expert_dialog" title="选择专家" style="font-size: 120%">
    <ul>
        <li>所在地区：<select id="expert_province_select"><option value="">选择省份</option></select> <select id="expert_city_select"><option value="">选择城市</option></select></li>
        <li>专家类型：<select id="expert_type_select"><option value="">选择专家类型</option></select></li>
        <li><button type="button" id="load_expert_button">获得专家</button><select id="expert_select"><option value="">选择专家</option></select></li>
    </ul>
</div>
<div id="expert_dialog" title="分配专家" style="font-size: 120%">
    <ul>
        <li>评审专家组成员</li>
        <li></li>
        <li id="e0_li">专家组长：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e1_li">专家一&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e2_li">专家二&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e3_li">专家三&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e4_li">专家四&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e5_li" style="display: none;">专家五&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e6_li" style="display: none;">专家六&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e7_li" style="display: none;">专家七&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
        <li id="e8_li" style="display: none;">专家八&nbsp;&nbsp;：<input type="text" class="select-expert-text" readonly="readonly"/><input type="hidden" class="select-expert-hidden"/></li>
    </ul>
</div>
<table style="margin-bottom: 10px" width="98%" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td width="15" style="padding: 0px" align="left">
            <select id="QUERY_SELECT">
                <option value="unit">项目单位</option>
            </select></td>
        <td width="15" id="QUERY_TD"><input type="text" value="" id="QUERY_CONDITION"/></td>
        <td align="left"><button type="button" id="QUERY_BUTTON"><img src="../css/blueprint/plugins/buttons/icons/magnifier.png" alt=""/>查询</button></td>
    </tr>
</table>
<table id="planDataTable" class="tablesorter" style="margin-top: 0px" width="98%" align="center" cellpadding="2" cellspacing="2">
    <thead>
        <tr>
            <th width="10%">项目登记号</th>
            <th width="12%">项目单位</th>
            <th width="12%">项目名称</th>
            <th width="10%">项目性质</th>
            <th width="10%">项目规模</th>
            <th width="10%">矿种</th>
            <th width="10%">开采方式</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody id="planDataBody">
    </tbody>
    <tbody id="pageBar">
        <tr>
            <td colspan="7" nowrap="nowrap" width="100%">
                <table>
                    <tbody>
                        <tr>
                            <td height="25"><button type="button" class="first-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_first.png" alt=""/></button></td>
                            <td><button type="button" class="previous-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_previous.png" alt=""/></button></td>
                            <td width="20%"><span class="page-index-selector" style=""></span></td>
                            <td><button type="button" class="next-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_next.png" alt=""/></button></td>
                            <td><button type="button" class="last-page"><img src="../css/blueprint/plugins/buttons/icons/resultset_last.png" alt=""/></button></td>
                            <td><select class="page-size-selector">
                                    <option value="10" selected="selected">10</option>
                                    <option value="20">20</option>
                                    <option value="30">30</option>
                                </select></td>
                            <td width="80%">&nbsp;</td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>
</body>
</html>